package cn.itcast.ReducerJoin;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

public class ReducerJoinMapper extends Mapper<LongWritable, Text, Text, Text> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        FileSplit fileSplit = (FileSplit) context.getInputSplit();
        String name = fileSplit.getPath().getName();
        if (name.equals("orders.txt")) {
            String[] split = value.toString().split(",");
            context.write(new Text(split[2]), value);
        } else {
            String[] split = value.toString().split(",");
            context.write(new Text(split[0]), value);
        }
    }
}
